package com.hzhr.iot.device.convertor.custom;

import com.hzhr.iot.device.convertor.CollectDeviceConvertor;
import com.hzhr.iot.device.entity.ext.*;
import com.hzhr.iot.device.model.collectDevice.CollectDeviceModel;
import com.hzhr.iot.device.model.regulatorDevice.RegulatorDeviceModel;
import org.springframework.stereotype.Service;

@Service
public class CollectDeviceCustomConvertor extends CollectDeviceConvertor {
    @Override
    public RegulatorDeviceModel ext2regulatorDeviceModel(CollectDeviceEntityExt in) {
        RegulatorDeviceModel result = super.ext2regulatorDeviceModel(in);
        OptionsEntityExt ext1 = in.getCategoryExt();
        if (ext1 != null) {
            result.setCategoryDes(ext1.getDes());
        }
        CollectDeviceTypeEntityExt ext2 = in.getTypeExt();
        if (ext2 != null) {
            result.setTypeDes(ext2.getDes());
        }
        return result;
    }

    @Override
    public CollectDeviceModel ext2collectDeviceModel(CollectDeviceEntityExt in) {
        //已转换字段 iotDeviceDes prodFactoryId currentValveStatusDes iotDeviceSimTypeCode iotDeviceSimTypeDes typeDes iotDeviceCode currentValveStatusCode prodFactoryDes iotDeviceSimNo
        CollectDeviceModel result = super.ext2collectDeviceModel(in);
        result.setCurrentValveStatusCode(in.getCurrentValveStatusCode());
        IotDeviceEntityExt ext1 = in.getIotDeviceExt();
        if (ext1 != null) {
            result.setIotDeviceCode(ext1.getCode());
            result.setTypeId(ext1.getTypeId());
            result.setIotDeviceDes(ext1.getDes());
            result.setIotDeviceSimNo(ext1.getSimNo());
            result.setIotDeviceLongitude(ext1.getLongitude());
            result.setIotDeviceLatitude(ext1.getLatitude());
            OptionsEntityExt ext2 = ext1.getSimTypeExt();
            if (ext2 != null) {
                result.setIotDeviceSimTypeDes(ext2.getDes());
            }
            IotDeviceTypeEntityExt ext3 = ext1.getTypeExt();
            if (ext3 != null) {
                result.setIotDeviceTypeDes(ext3.getDes());
            }
            UserCompanyEntityExt ext4 = ext1.getCompanyExt();
            if (ext4 != null) {
                result.setIotDeviceCompanyName(ext4.getName());
            }
        }
        CollectDeviceTypeEntityExt ext2 = in.getTypeExt();
        if (ext2 != null) {
            result.setTypeDes(ext2.getDes());
            ProdFactoryEntityExt ext3 = ext2.getProdFactoryExt();
            if (ext3 != null) {
                result.setProdFactoryId(ext3.getId());
                result.setProdFactoryDes(ext3.getDes());
                result.setProdFactoryIotCompanyId(ext3.getIotCompanyId());
            }
        }
        OptionsEntityExt ext3 = in.getCurrentValveStatusExt();
        if (ext3 != null) {
            result.setCurrentValveStatusDes(ext3.getDes());
        }
        OptionsEntityExt ext4 = in.getPressureUnitExt();
        if (ext4 != null) {
            result.setPressureUnitDes(ext4.getDes());
        }
        return result;
    }
}

